package com.sayd.sjxc.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.sayd.sjxc.bean.UserInfoBean;


public class VIPConfig {

	private Context context;
	public static VIPConfig dpConfig;
	private DPSharePreference mSharePreference;

	public VIPConfig(Context context) {
		super();
		this.context = context;
		mSharePreference = new DPSharePreference();
	}

	public static VIPConfig getInstance(Context context) {
		if (dpConfig == null) {
			dpConfig = new VIPConfig(context);
		}
		return dpConfig;
	}

	public SharedPreferences getSharePreferences() {
		return mSharePreference.getSharePreferences();
	}

	/**
	 * 是否首次启动
	 * */
	public void setIsFirst(boolean flag) {
		mSharePreference.setIsFirst(flag);
	}

	/**
	 * 是否首次启动
	 * */
	public boolean getIsFirst() {
		return mSharePreference.isFirst();
	}

	/**
	 * 保存用户信息
	 * */
	public void setUserInfo(UserInfoBean user, boolean flag) {
		mSharePreference.setUserCloudId(user.getCloudID());
		mSharePreference.setUserMoile(user.getMobile());
		mSharePreference.setUserName(user.getName());
		mSharePreference.setUserRoleID((String)user.getRoleID());
		mSharePreference.setLoginToken(user.getToken());
		mSharePreference.setNickName(user.getNickName());

		if (!GeneralUtil.isEmpty(user.getIconurl())) {
			if (user.getIconurl().equals("NoIcon")) {
				mSharePreference.setUserIcon("");
			} else {
				mSharePreference.setUserIcon(user.getIconurl());
			}
		} else {
			mSharePreference.setUserIcon("");
		}

		mSharePreference.setUserStatus(flag);

	}



	/**
	 * 获取RoleId
	 * */
	public String getUserRoleId() {
		return mSharePreference.getUserRoleID();

	}

	/**
	 * 获取版本信息
	 * */
	public String getVersion(){

		return mSharePreference.getVersionInfo();
	}

	/**
	 * 更新版本信息
	 * */
	public void setVersion(String versionInfo){

		mSharePreference.setVersionInfo(versionInfo);
	}


	/**
	 * 获取用户手机号码
	 * */
	public String getUserMoile() {
		return mSharePreference.getUserMobile();
	}


	/**
	 * 更新密碼
	 * */
	public void updatePassword(String pwd) {
		mSharePreference.setUserPassword(pwd);
	}

	/**
	 * 获取当前用户登录状态
	 * */
	public boolean getLoginStatus() {
		return mSharePreference.getUserStatus();
	}

	/**
	 * 修改用户登录状态
	 * */
	public void updateLoginStatus(boolean flag) {
		mSharePreference.setUserStatus(flag);
	}

	/**
	 * 获取用户名
	 * */
	public String getUsername() {
		return mSharePreference.getUserName();
	}

	/**
	 * 获取用户云码
	 * */
	public String getCloudId() {
		return mSharePreference.getUserCloudId();
	}


	/**
	 * 获取登录token
	 * */
	public String getNewLoginToken() {
		return mSharePreference.getLoginToken();
	}


	/**
	 * 修改密码登录
	 * */
	public void setFlagByPwd(boolean flag) {
		mSharePreference.setLoginByPwd(flag);
	}

	/**
	 * 获取密码
	 * */
	public String getPassword() {
		return mSharePreference.getUserPassword();
	}

	/**
	 * 获取头像地址
	 * */
	public String getUserIconUrl() {
		return mSharePreference.getUserIcon();
	}

	/**
	 * 修改头像地址
	 * */
	public void updateUserIcon(String iconUrl) {
		mSharePreference.setUserIcon(iconUrl);
	}


	/**
	 * 判断是否显示引导页
	 */
	public String getVersionNames() {
		return mSharePreference.getVersionName();
	}


	/**
	 * 判断是否显示引导页
	 */
	public void setVersionNames(String versionNames) {
		mSharePreference.setVersionName(versionNames);
	}


	public class DPSharePreference {

		public static final String KEY_SHAREDPREFERENCES = "DPConfig";
		public static final String USER_ID = "userID";
		public static final String ROLE_ID = "userRoleID";
		public static final String USER_NAME = "userName";
		public static final String USER_PASSWORD = "userPassword";
		public static final String CLOURDID = "userCloudId";
		public static final String USER_MOBILE = "userMobile";
		public static final String USER_STATUS = "userStatus";
		public static final String USER_REGISTER_STATUS = "userRegisterStatus";
		public static final String LOGIN_DATE = "loginDate";
		public static final String SEARCH_RECORD = "searchRecord";
		public static final String LOGIN_TOKEN = "loginToken";
		public static final String USER_VIP = "user_vip";
		public static final String ISTEMPORARYPWD = "IsTemporaryPwd";
		public static final String USER_ICON = "userIcon";
		public static final String REMEMBER_PWD = "remember_password";
		public static final String IS_FIRST = "isFirst";
		public static final String VERSION_INFO = "VersionInfo";
		public static final String VERSION_NAME = "VersionName";
		public static final String NICKNAME = "NickName";

		private SharedPreferences sharePreferences;

		public DPSharePreference() {
			super();
			sharePreferences = context.getSharedPreferences(
					KEY_SHAREDPREFERENCES, Context.MODE_PRIVATE);
		}

		public SharedPreferences getSharePreferences() {
			return sharePreferences;
		}

		public void setUserID(String userid) {
			sharePreferences.edit().putString(USER_ID, userid).commit();
		}

		public String getUserID() {
			return sharePreferences.getString(USER_ID, "");
		}

		public void setUserName(String username) {
			sharePreferences.edit().putString(USER_NAME, username).commit();
		}

		public void setUserRoleID(String userid) {
			sharePreferences.edit().putString(ROLE_ID, userid).commit();
		}

		public String getUserRoleID() {
			return sharePreferences.getString(ROLE_ID, "");
		}

		public String getUserName() {
			return sharePreferences.getString(USER_NAME, "");
		}

		public void setUserPassword(String password) {
			sharePreferences.edit().putString(USER_PASSWORD, password).commit();
		}

		public String getUserPassword() {
			return sharePreferences.getString(USER_PASSWORD, "");
		}

		public void setUserCloudId(String cloudid) {
			sharePreferences.edit().putString(CLOURDID, cloudid).commit();
		}

		public String getUserCloudId() {
			return sharePreferences.getString(CLOURDID, "");
		}

		public void setUserMoile(String mobile) {
			sharePreferences.edit().putString(USER_MOBILE, mobile).commit();
		}

		public String getUserMobile() {
			return sharePreferences.getString(USER_MOBILE, "");
		}

		public void setUserIcon(String iconurl) {
			sharePreferences.edit().putString(USER_ICON, iconurl).commit();
		}

		public String getUserIcon() {
			return sharePreferences.getString(USER_ICON, "");
		}

		public void setUserStatus(boolean userid) {
			sharePreferences.edit().putBoolean(USER_STATUS, userid).commit();
		}

		public boolean getUserStatus() {
			return sharePreferences.getBoolean(USER_STATUS, false);
		}

		public void setSearchRecord(String search) {

			sharePreferences.edit().putString(SEARCH_RECORD, search).commit();
		}

		public String getSearchRecord() {
			return sharePreferences.getString(SEARCH_RECORD, "");
		}

		public void deleteSearchRecord() {

			sharePreferences.edit().putString(SEARCH_RECORD, "").commit();
		}

		public void setLoginByPwd(boolean userid) {
			sharePreferences.edit().putBoolean(ISTEMPORARYPWD, userid).commit();
		}

		public boolean getLoginByPwd() {
			return sharePreferences.getBoolean(ISTEMPORARYPWD, false);
		}

		public void setLoginToken(String search) {

			sharePreferences.edit().putString(LOGIN_TOKEN, search).commit();
		}

		public String getLoginToken() {
			return sharePreferences.getString(LOGIN_TOKEN, "");
		}

		public void setUserVip(int flag) {
			sharePreferences.edit().putInt(USER_VIP, flag).commit();
		}

		public int getUserVip() {
			return sharePreferences.getInt(USER_VIP, 0);
		}

		public void setRememberPwd(boolean flag) {
			sharePreferences.edit().putBoolean(REMEMBER_PWD, flag).commit();
		}

		public boolean getRememberPwd() {
			return sharePreferences.getBoolean(REMEMBER_PWD, false);
		}

		public void setIsFirst(boolean flag) {
			sharePreferences.edit().putBoolean(IS_FIRST, flag).commit();
		}

		public boolean isFirst() {
			return sharePreferences.getBoolean(IS_FIRST, true);
		}



		public void setVersionInfo(String str) {

			sharePreferences.edit().putString(VERSION_INFO, str).commit();
		}

		public String getVersionInfo() {
			return sharePreferences.getString(VERSION_INFO, "");
		}


		public void setVersionName(String flag) {
			sharePreferences.edit().putString(VERSION_NAME, flag).commit();
		}

		public String getVersionName() {
			return sharePreferences.getString(VERSION_NAME, "");
		}


		public void setNickName(String nickName) {

			sharePreferences.edit().putString(NICKNAME, nickName).commit();
		}

		public String getNickName() {
			return sharePreferences.getString(NICKNAME, "");
		}

	}

}
